define({});

$('#gotop').click(function() {
    $('body,html').animate({
            scrollTop: 0
        },
        800);
    return false;
});

$('#addBookMark').click(function() {
    try {
        window.external.addFavorite(location.href, '淘牛品――天天一元秒杀，价格超给力！');
    } catch (e) {
        try {
            window.sidebar.addPanel('淘牛品――天天一元秒杀，价格超给力！', location.href, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
    return false;
});

$(window).scroll(function() {
    scroll();
});

var w = $(window).height();
var white_fix_top = w - 175 - 517 + 60;

//$('#catlist_11_11 .white_fix').css('height',white_fix_top+'px');

var right_fix = (w - 630) / 2;
$('#catlist_11_11').css('margin-top', right_fix + 'px');
$('#catlist_11_11').show();

function scroll() {
    var t = $(document).scrollTop();
    var h = $(document).height();


    var fix_num = 175 - t;
    var white_fix = w - 517;
    var white_fix_top_scroll = white_fix_top + t;
    var white_fix_mid = w - t - 517 + 60 + t;


    if (t <= 175) {
        $('#catlist').addClass('cat-fix-top');
        $('#gotop').hide();

        //$('#catlist_11_11').addClass('cat-fix-top_11_11');
        //$('#catlist_11_11 .white_fix').css('height',white_fix_top_scroll+'px');
        //$('#catlist_11_11').css('top',fix_num+'px');

    } else if (t > 175 && (h - t) < 830) {
        $('#catlist').addClass('cat-fix-top');


        //$('#catlist_11_11').css('top','0px');
        //$('#catlist_11_11 .white_fix').css('height',white_fix_mid+'px');

    } else {
        $('#catlist').removeClass('cat-fix-top');
        $('#gotop').show();

        //$('#catlist_11_11').css('top','0px');
        //$('#catlist_11_11').removeClass('cat-fix-top_11_11');
        //$('#catlist_11_11 .white_fix').css('height',white_fix+'px');
    }

    if ((h - t) < 830) {
        $('#catlist').hide();
    } else {
        $('#catlist').show();
    }

}

$('#tx,#tj ').mouseover(function() {
    $('.txslide').removeClass('active');
    $(this).addClass('active');
    $('.txslidebody').hide();
    $("#" + this.id + 'body').show();
    require(['lib/jquery.lazyload'], function() {
        $("img.lazy").lazyload();
    });
    if (this.id === 'tj') {
        $('#pager').hide();
    } else {
        $('#pager').show();
    }
});

function share_set() {
    var id = $('#record_product_id').val();
    if (id !== '0') {
        if ($('#' + id)) {
            var share_text = $("#" + id + " .good_desc").html();
            var share_pic = $("#" + id + " .good_img").attr('src');
            var share_url = $("#" + id + " .good_url").attr('href');

            bdPic = share_pic;
            bdUrl = share_url;
            bdText = share_text;
            share_box(id, bdPic, bdUrl, bdText, '', function() {
                $.get('/user/public/share.html', {
                    goods_id: id
                }, function(data) {});
            });
        }
    }
}

//分享的方法
function share_box(id, Pic, Url, Text, Desc, Func) {
    if (Pic == '' || Pic == undefined) Pic = 'http://www.1zw.com/themes/1zw/assets/images/logo.jpg';
    if (Desc == '' || Desc == undefined) Desc = '【1折网官网】全场包邮1折起，每天早上准时十点特价新品等你抢！';
    if (Url == '' || Url == undefined) Url = 'http://www.1zw.com/';
    if (Text == '' || Text == undefined) Text = '【1折网官网】全场包邮1折起，每天早上准时十点特价新品等你抢！';
    //回调
    var callback = function() {};
    if (typeof(Func) == 'function') {
        callback = Func;
    }
	//微信
    $('#' + id + ' .share_weixin').unbind('click').bind('click', function() {
        d.close();
        var share = dialog({
            id: 'share_weixin',
            title: '分享到微信朋友圈',
            content: '<img src="http://www.1zw.com/themes/1zw/assets/images/qrcode-1zw.com.png" style="width:200px;height:200px">'
        });
        share.show();
        callback();
    });
	//qq，微博，新浪微博
    $('#' + id + ' .share_sqq,#' + id + ' .share_tsina,#' + id + ' .share_qzone').unbind('click').bind('click', function() {
        callback();
    });
    $('#' + id + ' .share_sqq').attr("href", "http://connect.qq.com/widget/shareqq/index.html?url=" + Url + "&title=" + Text + "&desc=" + Desc + "&pics=" + Pic);
    $('#' + id + ' .share_tsina').attr("href", "http://service.weibo.com/share/share.php?url=" + Url + "&title=" + Text + "&appkey=1343713053&searchPic=false&pic=" + Pic);
    $('#' + id + ' .share_qzone').attr("href", "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + Url + "&title=" + Text + "&desc=" + Desc + "&pics=" + Pic);
}

function good_function() {
    $(".thumbnail").mouseover(function() {
        var id = this.id;
        if (id != '') {
            $('#record_product_id').val(id);
            $('#' + id + ' .share-box').css('display', 'block');
            share_set();
        }
    });
    $(".thumbnail").mouseout(function() {
        var id = this.id;
        if (id != '') {
            $('#' + id + ' .share-box').css('display', 'none');
        }
    });
    /*
    window._bd_share_config = {
        common: {
            bdText: '【1折网官网】全场包邮1折起，每天早上准时十点特价新品等你抢！',
            bdDesc: '【1折网官网】全场包邮1折起，每天早上准时十点特价新品等你抢！',
            bdUrl: 'http://www.1zw.com',
            bdPic: '',
            onBeforeClick: function(cmd, config) {
                var id = $('#record_product_id').val();
                if (id !== '0') {
                    $.get('/user/public/share.html', {
                        goods_id: id
                    }, function(data) {});
                    if ($('#' + id)) {
                        var share_text = $("#" + id + " .good_desc").html();
                        var share_pic = $("#" + id + " .good_img").attr('src');
                        var share_url = $("#" + id + " .good_url").attr('href');
                        return {
                            bdText: share_text,
                            bdUrl: share_url,
                            bdPic: share_pic
                        };
                    }
                }

            }
        },
        share: [{
            "bdSize": 16
        }]
    };
    with(document)
        //$.getScript('http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion=' + ~(-new Date()));
    0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion=' + ~(-new Date() / 36e5)];
    */


}


$(document).ready(function() {
    good_function();
});


//=====日历签到请求====
$('.qdlabel').click(function() {
    $.ajax({
        url: "/user/sign/sign.html?t=" + new Date().getTime(),
        type: "GET",
        timeout: 5000,
        dataType: "json",
        success: function(data) {
            //alert(data.info);
            if ($('.qdlabel').html() != "您已签到" && data.state == "success") {
                $('.qdlabel').html('您已签到');
                var d = dialog({
                    /*
    				content:"<div class='qd_success'>" +
    						"<div class='qd_success_title'>恭喜你成功获得  <font color=#dd004e>5</font>  个积分</div>" +
    						"<div class='qd_success_content'>积分可参加免费兑换商品活动，详情请关注积分商城</div>" +
    						"</div>",		
                            */
                    content: "<div class='qd_success'>" +
                        "<div class='qd_success_title'>" + data.info + "</div>" +
                        "</div>",
                    quickClose: true,

                }).width(240).show();
                //d.show();
            } else {
                var d = dialog({
                    content: "<div class='qd_success'>" +
                        "<div class='qd_success_title'>" + data.info + "</div>" +
                        "</div>",
                    quickClose: true,

                }).width(240).show();
                //d.show();
            }
            if (data.status) {
                $('.qiandaodiv').remove();
                loadSign();
            }
        }
    });
});

function loadSign() {
    $('.qiandaodiv').remove();
    $.get('/user/sign/calendar', {
        t: new Date().getTime()
    }, function(html) {
        $(".qdlabel").parent().append(html);
        $('.qiandaodiv').fadeIn(500);
    }, 'html');
    return true;
}
$('.qdlabel').mouseover(function() {
    $('.qiandaodiv').stop(true);
    if ($('.qiandaodiv').length > 0) {
        $('.qiandaodiv').fadeIn(500);
        return true;
    } else {
        loadSign();
        return true;
    }
});

$('.qdlabel').mouseout(function() {
    $('.qiandaodiv').stop(true);
    $('.qiandaodiv').hide();
});
//========日历签到请求====END========

$(document).ready(function() {
    //复制邀请链接
    if ($("#invite_btn").length > 0) {
        $('#invite_btn').zclip({
            path: '/themes/1zw/assets/js/zclip/ZeroClipboard.swf',
            copy: function() {
                return $('#invite_url').val();
            }
        });
    }
});
//===============问号的提示内容==========
$(".tips_hold").mouseover(function() {
    var cont = '<div class="tip_box">' + $(this).data('content') + '</div>';
    var tips_hold = dialog({
        align: 'bottom',
        padding: 10,
        content: cont
    });
    tips_hold.show(this);
    $(".tips_hold").mouseout(function() {
        tips_hold.close(this);
    });
});